import 'package:flutter/material.dart';
class DemoAnamation extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('动画效果展示'),
      ),
      body: DemoText2()
    );
  }
}


class DemoText2 extends StatefulWidget {
   @override
  _DemoText2 createState() => _DemoText2();
}

class _DemoText2 extends State <DemoText2> with SingleTickerProviderStateMixin {
  @override
  _DemoText2() {
    controller = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 1)
    );
    down();
  }

  AnimationController controller;
  Animation<double> animation;
  String tip = '下拉';
  void onPress () {
    if (animation.isCompleted) {
      tip = '下拉';
      controller.reverse();
    } else {
      tip = '收起';
      controller.forward();
    }
  }

  void down () {
    animation = Tween<double>(begin: 0.0, end: 20.0)
    .animate(controller)
    ..addListener(() {
      print(animation.status);
      setState(() {});
    });
  }
  

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        FlatButton(
            child: Text(tip),
            onPressed: onPress,
        ),
        Container(
          child: const Text('wen zi 1', overflow: TextOverflow.clip), 
          height: animation.value
        ),
        Container(child: const Text('wen zi 1', overflow: TextOverflow.clip), height: animation.value),
        Container(child: const Text('wen zi 1', overflow: TextOverflow.clip), height: animation.value),
        Container(child: const Text('wen zi 1', overflow: TextOverflow.clip), height: animation.value),
      ]
    );
 
  }

  @override
  void dispose() {
    // 资源释放
    controller.dispose();
    super.dispose();
  }

}